package dice.sinanya.db.properties.game;

import dice.sinanya.db.tools.DbUtil;
import dice.sinanya.entity.EntityGame;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import static dice.sinanya.system.MessagesSystem.loginInfo;

/**
 * @author SitaNya
 * 日期: 2019-06-15
 * 电子邮箱: sitanya@qq.com
 * 维护群(QQ): 162279609
 * 有任何问题欢迎咨询
 * 类说明: 录入KP主群类
 */
public class InsertProperties {
    private static final Logger log = LogManager.getLogger(InsertProperties.class.getName());

    public void insertProperties(EntityGame entityGame) {
        try (Connection conn = DbUtil.getConnection()) {
            //language=MySQL
            String sql = "replace into test.gameProperties(botId,jrrpSwitch,jrrpInfo,welcomeSwitch,botList,deck,nameSwitch,ob,simple,rule,fireNext,fireNeedStop,fireAbort,fireAgentError,fireContinue,fireStop,fireAlreadyStop,fireResetNeedStop,fireReset,getName,obAlreadyInsert,obInsert,obRemove,obAlreadyRemove,obClear,obShow,obEmpty,welcomeClose,welcomeOpen,welcomeInsert,bgInfo,cocCard7Make,cocCard6Make,groupSwitchInfo,jrrpStart,jrrpStop,npcStart,npcStop,welcomeStart,welcomeStop,gasStart,gasStop,bgStart,bgStop,tzStart,tzStop,simpleStart,simpleStop,obStart,obStop,deckStart,deckStop,rankCantStart,rankStart,rankStop,ruleChange,ruleGet,ruleDefault,reply)  VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
            try (PreparedStatement ps = conn.prepareStatement(sql)) {
                ps.setString(1, String.valueOf(loginInfo.getLoginId()));
                ps.setBoolean(2, entityGame.isJrrpSwitch());
                ps.setString(3, entityGame.getJrrpInfo());
                ps.setBoolean(4, entityGame.isWelcomeSwitch());
                ps.setBoolean(5, entityGame.isBotList());
                ps.setBoolean(6, entityGame.isDeck());
                ps.setBoolean(7, entityGame.isNameSwitch());
                ps.setBoolean(8, entityGame.isOb());
                ps.setBoolean(9, entityGame.isSimple());
                ps.setBoolean(10, entityGame.isRule());
                ps.setString(11, entityGame.getFireNext("0"));
                ps.setString(12, entityGame.getFireNeedStop("0"));
                ps.setString(13, entityGame.getFireAbort("0"));
                ps.setString(14, entityGame.getFireAgentError("0"));
                ps.setString(15, entityGame.getFireContinue("0"));
                ps.setString(16, entityGame.getFireStop("0"));
                ps.setString(17, entityGame.getFireAlreadyStop("0"));
                ps.setString(18, entityGame.getFireResetNeedStop("0"));
                ps.setString(19, entityGame.getFireReset("0"));
                ps.setString(20, entityGame.getGetName("0"));
                ps.setString(21, entityGame.getObAlreadyInsert("0"));
                ps.setString(22, entityGame.getObInsert("0"));
                ps.setString(23, entityGame.getObRemove("0"));
                ps.setString(24, entityGame.getObAlreadyRemove("0"));
                ps.setString(25, entityGame.getObClear("0"));
                ps.setString(26, entityGame.getObShow("0"));
                ps.setString(27, entityGame.getObEmpty("0"));
                ps.setString(28, entityGame.getWelcomeClose("0"));
                ps.setString(29, entityGame.getWelcomeOpen("0"));
                ps.setString(30, entityGame.getWelcomeInsert("0"));
                ps.setString(31, entityGame.getBgInfo("0"));
                ps.setString(32, entityGame.getCocCard7Make("0"));
                ps.setString(33, entityGame.getCocCard6Make("0"));
                ps.setString(34, entityGame.getGroupSwitchInfo("0"));
                ps.setString(35, entityGame.getJrrpStart("0"));
                ps.setString(36, entityGame.getJrrpStop("0"));
                ps.setString(37, entityGame.getNpcStart("0"));
                ps.setString(38, entityGame.getNpcStop("0"));
                ps.setString(39, entityGame.getWelcomeStart("0"));
                ps.setString(40, entityGame.getWelcomeStop("0"));
                ps.setString(41, entityGame.getGasStart("0"));
                ps.setString(42, entityGame.getGasStop("0"));
                ps.setString(43, entityGame.getBgStart("0"));
                ps.setString(44, entityGame.getBgStop("0"));
                ps.setString(45, entityGame.getTzStart("0"));
                ps.setString(46, entityGame.getTzStop("0"));
                ps.setString(47, entityGame.getSimpleStart("0"));
                ps.setString(48, entityGame.getSimpleStop("0"));
                ps.setString(49, entityGame.getObStart("0"));
                ps.setString(50, entityGame.getObStop("0"));
                ps.setString(51, entityGame.getDeckStart("0"));
                ps.setString(52, entityGame.getDeckStop("0"));
                ps.setString(53, entityGame.getRankCantStart("0"));
                ps.setString(54, entityGame.getRankStart("0"));
                ps.setString(55, entityGame.getRankStop("0"));
                ps.setString(56, entityGame.getRuleChange("0"));
                ps.setString(57, entityGame.getRuleGet("0"));
                ps.setString(58, entityGame.getRuleDefault("0"));
                ps.setString(59,entityGame.getReply());
                ps.executeUpdate();
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
    }
}